#include <cstdio>

using namespace std;

int month_day[12] = {31, 28, 31, 30, 31, 30,
                     31, 31, 30, 31, 30, 31};
                     
bool is_leap(int year)
{
	if (year % 400 == 0 || year % 100 != 0 && year % 4 == 0)
	{
		return true;
	}
	return false;
}

int end_day_of_month(int year, int month)
{
	if (is_leap(year) && month == 2)
	{
		return 29;
	}
	return month_day[month-1];
}

class CDate
{
	private:
		int year, month, day;
		
		void format()
		{
			for (; month < 1; month += 12, year -= 1) {}
			for (; month > 12; month -= 12, year += 1) {}
			for (; day < 1; )
			{
				if ((month > 2) && is_leap(year)
				    || (month < 3) && is_leap(year - 1))
				{
					day += 366;
					year -= 1;
				}
				else
				{
					day += 365;
					year -= 1;
				}
			}
			for (; day > 366; )
			{
				if ((month < 3) && is_leap(year)
				    || (month > 2) && is_leap(year + 1))
				{
					day -= 366;
					year += 1;
				}
				else
				{
					day -= 365;
					year += 1;
				}
			}
			// Now day in range 1~365
			for (; day > end_day_of_month(year, month); )
			{
				day -= end_day_of_month(year, month);
				month += 1;
				if (month == 13)
				{
					month = 1;
					year += 1;
				}
			}
		}
		
	public:
		CDate(int _year=1970, int _month=1, int _day=1)
		{
			Assign(_year, _month, _day);
		}
		
		void Assign(int _year, int _month, int _day)
		{
			year = _year;
			month = _month;
			day = _day;
			format();
		}
		
		void print()
		{
			printf("Date: %04d-%02d-%02d\n", year, month, day);
		}
		
		CDate operator+(const int _day)
		{
			CDate rtn(*this);
			rtn.day += _day;
			rtn.format();
			return rtn;
		}
		
		CDate operator-(const int _day)
		{
			CDate rtn(*this);
			rtn.day -= _day;
			rtn.format();
			return rtn;
		}
};

int main()
{
	CDate date(2020, 1, 1);
	date.print();  // 2020-01-01
	
	date = date + 31;
	date.print();  // 2020-02-01
	
	date = date + 365;
	date.print();  // 2021-01-31
	
	date = date + 365;
	date.print();  // 2022-01-31
	
	date = date - 31;
	date.print();  // 2021-12-31
	
	date = date - 300;
	date.print();  // 2021-03-06
	
	date = date - 430;
	date.print();  // 2020-01-01
	
	return 0;
}
